<template>
<div class="factory-delivery">
  <el-tabs v-model="tabValue" @tab-click="documentProcessChoose">
    <el-tab-pane label="发货通知单" name="1">
      <noticeOfDeliveryVue ref="nd" :bus="bus" @fromND="updateData" :editable="tabOne" :datas="saveData.documentProcess_fd_notice"></noticeOfDeliveryVue>
    </el-tab-pane>
    <el-tab-pane  label="出厂确认" name="2">
      <factoryConfirmationVue :bus="bus"  @fromFC="updateData"  :editable="tabTwo" :datas="saveData.documentProcess_fd_confirm"></factoryConfirmationVue>
    </el-tab-pane>
  </el-tabs>
</div>
</template>

<script>
import noticeOfDeliveryVue from './components/noticeOfDeliveryVue.vue'
import factoryConfirmationVue from './components/factoryConfirmationVue.vue'

export default {
  created(){
    let self = this;
    this.allData = _.cloneDeep(this.saveData);

    this.bus.$on('bind-new-ftc', function () {
      self.hasBind = true;
    });
  },
  updated(){
  },
  watch: {
    datas(newValue, oldValue){
      this.saveData = _.cloneDeep(newValue);
      this.allData = _.cloneDeep(newValue);
    }
  },
  components: {
    noticeOfDeliveryVue,
    factoryConfirmationVue
  },
  data() {
    return {
      saveData: {
          //发货通知
          documentProcess_fd_notice: {
            id: '',
            formInstId: '',
            attachedFiles: [],

            //绑定的外贸订单id
            bindingFormInstId: '',

            orderCode: '',
            buyerName: '',
            documentprocess_fdn_bindFContracts: [],

            documentprocess_fdn_bindDContracts: [],

            documentprocess_fdn_contracts: '',

            //发货时间
            documentprocess_fdn_time: '',
            //交易方式
            documentprocess_fdn_tradeTerm: '',

            //海关编码
            documentprocess_fdn_hscode: '',

            //other
            documentprocess_fdn_other: '',

            //工厂联系方式
            documentprocess_fdn_fc_factoryName: '',
            documentprocess_fdn_fc_dff_contacts:[ 
              {
                name: '',
                tel: '',
                email: '',
                qq: '',
                wechat: '',
                factoryName: ''
              }],

            //物流联系方式
            documentprocess_fdn_lcc_logisticName: '',
            documentprocess_fdn_lcc_dfl_contacts: [
              {
                name: '',
                tel: '',
                email: '',
                qq: '',
                wechat: ''
              }
            ],

            documentprocess_deliDetail_total_number: '', //数量总和
            documentprocess_deliDetail_total_amount: '', //金额总和

            //发货明细
            documentprocess_deliDetail: [
              {
                dd_products: '',
                dd_description: '',
                dd_quantity: '',
                dd_price: '',
                dd_lineAmount: ''
              }
            ]
          },

          //出厂确认
          documentProcess_fd_confirm: {
            id: '',
            formInstId: '',
            attachedFiles: []
          }
      },
      all: {},
      hasBind: false,
      tabValue: '1'
    }
  },
  props: {
    datas: {
      type: Object,
      required: true
    },
    tabOne: {
      type: Boolean,
      required: true
    },
    tabTwo: {
      type: Boolean,
      required: true
    },
    bus: {
      type: Object,
      required: true
    }
  },
  methods: {
    /**
     * 工厂发货 将最新的数据传递给 最外层组件
     */
    emitToParent(){
      this.$emit("fromFD", "documentprocess_fd", this.allData);
    },

    /**
     * 工厂发货子组件 更新数据
     * @param {String} key 子组件字段
     * @param {Object}  value
     */
    updateData(key, value){
      let temp = _.cloneDeep(this.allData);
      temp[key] = value;
      this.allData = _.cloneDeep(temp);
      this.emitToParent();
    },
    documentProcessChoose(index, event) {
    }
  }
}
</script>

<style scoped lang="scss">
.factory-delivery {
}
</style>
